<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>浏览器本地存储-sessionStorage</title>
</head>
<body>
<h2>
    sessionStorage
</h2>
<button onclick="saveData()">点我保存一个数据</button>
<button onclick="readData()">点我读取一个数据</button>
<button onclick="delData()">点我删除一个数据</button>
<button onclick="clearData()">点我清空一个数据</button>
<script type="text/javascript">
    let p = {name: '纥石烈志宁', age: 10}
    function saveData() {
        sessionStorage.setItem("msg", "hello")
        sessionStorage.setItem("message", JSON.stringify(p))
    }
    function readData() {
        var msg = sessionStorage.getItem("msg");
        var message = sessionStorage.getItem("message");
        console.log('msg---', msg)
        console.log('message---', JSON.parse(message))
    }
    function delData() {
        sessionStorage.removeItem('msg')
    }
    function clearData() {
        sessionStorage.clear()
    }

</script>
</body>
</html>